﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace FrameWork.Lib.Serialization
{
    public partial class BaseXMLType
    {
        public BaseXMLType()
            : base()
        {
        }

        public BaseXMLType(Exception ex)
            : base()
        {
            AddResult(ex);
        }

        public virtual string Validate()
        {
            return "";
        }

        [System.Runtime.Serialization.DataMember()]
        public Result Result { get; set; }


        //[XmlIgnoreAttribute()]
        [XmlIgnore()]
        public string Xml
        {
            get
            {
                return Serializer.ToXml(this);
            }
        }

        public void AddResult(Exception pException)
        {
            AddResult(pException.Message, ResultSeverityType.Critical);
        }

        public void AddResult(string pMessage, ResultSeverityType pSeverity)
        {
            Result tResult = new Result();
            tResult.Message = pMessage;
            tResult.Severity = pSeverity;

            if (Result == null)
            {
                Result = tResult;
            }
            else
            {
                Result.SubResultList.Add(tResult);
            }
        }

        public void AddResult(Result pResult)
        {
            if (Result == null)
            {
                Result = new Result();
            }
            Result.AddResult(pResult);
        }

    }



}
